import axios from 'axios'

const state = {
  rectifyItems: [],
  rectifyCascader: [],
  rectifyCategories: []
}

const mutations = {
  setRectifyItems(state, payload) {
    state.rectifyCascader = payload;
    let rectifyCategories = [];
    for (let i = 0; i < payload.length; i++) {
      rectifyCategories.push(payload[i].value);
    }
    state.rectifyCategories = rectifyCategories;
  }
}

const actions = {
  loadRectifyItems({ commit, rootGetters }) {
    axios.post("api/load_params/", {
      user: rootGetters.userbase,
      params: ['rectifyItems']
    }).then(response => {
      if (response.data.status === 0) {
        commit("setRectifyItems", response.data.params.rectifyItems);
      }
      else {
        console.log(response.data)
      }
    }).catch(exception => {
      console.log(exception)
    });
  },
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}